
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.
The extglob npm package provides extended globbing capabilities with support for advanced pattern matching. It allows users to create more complex and flexible glob patterns for matching file paths and strings.
Basic Pattern Matching
This feature allows users to create basic pattern matching using extended glob syntax. The example demonstrates a pattern that matches 'ad', 'abd', or 'acd'.
const extglob = require('extglob');
const pattern = 'a?(b|c)d';
console.log(extglob(pattern)); // => 'a?(b|c)d'
Negation
This feature allows users to create patterns that exclude certain matches. The example demonstrates a pattern that matches anything except 'a' or 'b'.
const extglob = require('extglob');
const pattern = '!(a|b)';
console.log(extglob(pattern)); // => '!(a|b)'
Character Classes
This feature allows users to create patterns using character classes. The example demonstrates a pattern that matches 'a' followed by any character except 'b', followed by 'c'.
const extglob = require('extglob');
const pattern = 'a[!b]c';
console.log(extglob(pattern)); // => 'a[!b]c'
Multiple Patterns
This feature allows users to create patterns that match one or more occurrences of the specified patterns. The example demonstrates a pattern that matches 'abd', 'abcd', 'abbcd', etc.
const extglob = require('extglob');
const pattern = 'a+(b|c)d';
console.log(extglob(pattern)); // => 'a+(b|c)d'
Micromatch is a powerful globbing library that supports advanced pattern matching features similar to extglob. It is known for its speed and accuracy in matching file paths and strings. Compared to extglob, micromatch offers a more comprehensive set of features and better performance.
Minimatch is another popular globbing library that provides pattern matching capabilities. It is simpler and more lightweight compared to extglob, making it suitable for basic globbing needs. However, it lacks some of the advanced features provided by extglob.
Glob is a widely-used library for matching file paths using glob patterns. It is part of the Node.js ecosystem and provides a robust set of features for file system operations. While it supports basic globbing, it does not offer the extended pattern matching capabilities of extglob.
Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save extglob
Heads up!: This library only supports extglobs, to handle full glob patterns and other extended globbing features use micromatch instead.
The main export is a function that takes a string and options, and returns an object with the parsed AST and the compiled .output
, which is a regex-compatible string that can be used for matching.
var extglob = require('extglob');
console.log(extglob('!(xyz)*.js'));
Extended globbing patterns can be defined as follows (as described by the bash man page):
pattern | regex equivalent | description |
---|---|---|
?(pattern-list) | `(... | ...)?` |
*(pattern-list) | `(... | ...)*` |
+(pattern-list) | `(... | ...)+` |
@(pattern-list) | `(... | ...)` [1] |
!(pattern-list) | N/A | Matches anything except one of the given pattern(s) |
Convert the given extglob
pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST.
Params
pattern
{String}options
{Object}returns
{String}Example
var extglob = require('extglob');
console.log(extglob('*.!(*a)'));
//=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
Takes an array of strings and an extglob pattern and returns a new array that contains only the strings that match the pattern.
Params
list
{Array}: Array of strings to matchpattern
{String}: Extglob patternoptions
{Object}returns
{Array}: Returns an array of matchesExample
var extglob = require('extglob');
console.log(extglob.match(['a.a', 'a.b', 'a.c'], '*.!(*a)'));
//=> ['a.b', 'a.c']
Returns true if the specified string
matches the given extglob pattern
.
Params
string
{String}: String to matchpattern
{String}: Extglob patternoptions
{String}returns
{Boolean}Example
var extglob = require('extglob');
console.log(extglob.isMatch('a.a', '*.!(*a)'));
//=> false
console.log(extglob.isMatch('a.b', '*.!(*a)'));
//=> true
Returns true if the given string
contains the given pattern. Similar to .isMatch
but the pattern can match any part of the string.
Params
str
{String}: The string to match.pattern
{String}: Glob pattern to use for matching.options
{Object}returns
{Boolean}: Returns true if the patter matches any part of str
.Example
var extglob = require('extglob');
console.log(extglob.contains('aa/bb/cc', '*b'));
//=> true
console.log(extglob.contains('aa/bb/cc', '*d'));
//=> false
Takes an extglob pattern and returns a matcher function. The returned function takes the string to match as its only argument.
Params
pattern
{String}: Extglob patternoptions
{String}returns
{Boolean}Example
var extglob = require('extglob');
var isMatch = extglob.matcher('*.!(*a)');
console.log(isMatch('a.a'));
//=> false
console.log(isMatch('a.b'));
//=> true
Convert the given extglob
pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST.
Params
str
{String}options
{Object}returns
{String}Example
var extglob = require('extglob');
console.log(extglob.create('*.!(*a)').output);
//=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
Returns an array of matches captured by pattern
in string
, or null
if the pattern did not match.
Params
pattern
{String}: Glob pattern to use for matching.string
{String}: String to matchoptions
{Object}: See available options for changing how matches are performedreturns
{Boolean}: Returns an array of captures if the string matches the glob pattern, otherwise null
.Example
var extglob = require('extglob');
extglob.capture(pattern, string[, options]);
console.log(extglob.capture('test/*.js', 'test/foo.js'));
//=> ['foo']
console.log(extglob.capture('test/*.js', 'foo/bar.css'));
//=> null
Create a regular expression from the given pattern
and options
.
Params
pattern
{String}: The pattern to convert to regex.options
{Object}returns
{RegExp}Example
var extglob = require('extglob');
var re = extglob.makeRe('*.!(*a)');
console.log(re);
//=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/
Available options are based on the options from Bash (and the option names used in bash).
Type: boolean
Default: undefined
When enabled, the pattern itself will be returned when no matches are found.
Alias for options.nullglob, included for parity with minimatch.
Type: boolean
Default: undefined
Functions are memoized based on the given glob patterns and options. Disable memoization by setting options.cache
to false.
Type: boolean
Default: undefined
Throw an error is no matches are found.
Last run on December 21, 2017
# negation-nested (49 bytes)
extglob x 2,228,255 ops/sec ±0.98% (89 runs sampled)
minimatch x 207,875 ops/sec ±0.61% (91 runs sampled)
fastest is extglob (by 1072% avg)
# negation-simple (43 bytes)
extglob x 2,205,668 ops/sec ±1.00% (91 runs sampled)
minimatch x 311,923 ops/sec ±1.25% (91 runs sampled)
fastest is extglob (by 707% avg)
# range-false (57 bytes)
extglob x 2,263,877 ops/sec ±0.40% (94 runs sampled)
minimatch x 271,372 ops/sec ±1.02% (91 runs sampled)
fastest is extglob (by 834% avg)
# range-true (56 bytes)
extglob x 2,161,891 ops/sec ±0.41% (92 runs sampled)
minimatch x 268,265 ops/sec ±1.17% (91 runs sampled)
fastest is extglob (by 806% avg)
# star-simple (46 bytes)
extglob x 2,211,081 ops/sec ±0.49% (92 runs sampled)
minimatch x 343,319 ops/sec ±0.59% (91 runs sampled)
fastest is extglob (by 644% avg)
This library has complete parity with Bash 4.3 with only a couple of minor differences.
options.contains
to true.Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
step
to… more | homepageCommits | Contributor |
---|---|
49 | jonschlinkert |
2 | isiahmeadows |
1 | doowb |
1 | devongovett |
1 | mjbvz |
1 | shinnn |
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on December 21, 2017.
FAQs
Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.
The npm package extglob receives a total of 14,341,326 weekly downloads. As such, extglob popularity was classified as popular.
We found that extglob demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.